﻿@model BackEnd.Models.ImageLastProjectModel
@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
    $(document).ready(function () {
        CreateTextarea("Info", 450, 300);
    });
</script>
<script>
    function ValidateData() {
        $.ajax({
            url: '/ImageLastProject/Create',
            type: 'POST',
            data: {
                type: $('#Type').val(),
                image: $('#iphFileNameImage').val(),
                redirectUrl: $('#RedirectUrl').val(),
                info: $('#Info').val(),
            },
            success: function (data) {
                switch (data) {
                    case -1:
                        window.location("/Account/Login");
                        break;
                    case -2:
                        window.location("/Account/Login");
                        break;
                    default:
                        alert('Insert Success!');
                }
            }
        });
    }

    function RemoveFileUpload(spanId) {
        $("#" + spanId).remove();

        $("#iphFileNameImage").val('');               
    }
</script>
<h2>Create Image Last Project</h2> 
<table>
    <tr>
        <td>@Html.LabelFor(m=>m.Type)</td>
        <td>
            @Html.DropDownListFor(m=>m.Type, new SelectList(Model.ListImageLastProjectType, "Id", "Name"))    
        </td>
    </tr>
    <tr>
        <td>@Html.LabelFor(m=>m.Image)</td>
        <td>
            <input type="file" id="ipfImage"/>            
                <script type="text/javascript">
                    $('#ipfImage').uploadify({
                        'script': '/ImageLastProject/UploadFile',
                        'uploader': '/Scripts/uploadify/uploadify.swf',
                        'buttonImg': '/Scripts/uploadify/btn_select.png',
                        'cancelImg': '/Scripts/uploadify/cancel.png',
                        'folder': '/ImageLastProject',
                        'width': '51',
                        'height': '23',
                        'fileExt': '*.jpg;*.gif;*.png;',
                        'fileDesc': '*.jpg;*.gif;*.png;',
                        'sizeLimit': '52428800',
                        'queueSizeLimit': 10,
                        'multi': false,
                        'auto': true,
                        'scriptData': { RequireUploadifySessionSync: true, SecurityToken: UploadifyAuthCookie, SessionId: UploadifySessionId },
                        'onQueueFull': function (event, queueID, fileObj) {
                        },
                        'onSelect': function (event, queueID, fileObj) {
                        },
                        'onError': function (event, queueID, fileObj, obj) {
                        },
                        'onProgress': function (event, queueID, fileObj, obj) {
                        },
                        'onComplete': function (event, queueID, fileObj, response, data) {
                            var json = eval("(" + response + ")");
                            if (json.errorCode == 100) {
                                $('#iphFileNameImage').val(json.fileName);
                                var spanId = json.fileName.replace(/\./gi, "_");
                                var str = "<span id=" + spanId + ">" + json.fileName + " (<a href=javascript:RemoveFileUpload('" + spanId + "')>Xóa</a>)</span><br/>";
                                $("#fileQueueImage").html(str);
                            } else {
                            }
                        },
                        'onAllComplete': function () {
                        }
                    });
            </script>
            <div id="fileQueueImage">                 
            </div>
        </td>
    </tr> 
    <tr>
        <td>@Html.LabelFor(m=>m.RedirectUrl)</td>
        <td>
            @Html.TextBoxFor(m=>m.RedirectUrl)    
        </td>
    </tr>
    <tr>
        <td>@Html.LabelFor(m=>m.Info)</td>
        <td>
            @Html.TextAreaFor(m=>m.Info)    
        </td>
    </tr>           
    <tr>        
        <td>
            <input type="hidden" id="iphFileNameImage"/>          
        </td>
        <td>
            <img class="NFButtonLeft NFh" src="/Content/Img/0.png"><input type="button" class="NFButton NFh" value="Create" onclick="ValidateData()" /><img class="NFButtonRight NFh" src="/Content/Img/0.png">
            @Html.ActionLink("Back", "Index", "ImageLastProject")
        </td>
    </tr>
</table>
